/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.shsc.facade;

import com.bionic.shsc.dao.interfaces.ITestDAO;
import com.bionic.shsc.db.DB;
import com.bionic.shsc.entities.QuestionData;
import com.bionic.shsc.entities.TestData;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.List;

/**
 *
 * @author ant
 */
public class TestFacade {
   
    // stores question and answer data
    private class CalcData {
      private int questionID;
      private int questionType;
      private int questionMinAnswer;
      private int questionWeight;
      
      private int answerID;
      private int answerWeight;
    }
    
    
    
    //Это в юзер-фасаде - т.к. пока данные нужны в одном объекте
    List<TestData> testList;
    
    // Вытянуть сюда данные теста (включить туда общую сумму балов по тесту)
    private TestData currentTest;
    
    private ITestDAO testDB;
    private int currentTestID;
    private ArrayList<QuestionData> questionList;
    private int currentQuestionNum;
    private QuestionData currentQuestion;
    
    private Dictionary<Integer,CalcData> questionAnswers;
    

    public void getTest(int testID) {
        questionList = getTestDB().getTestQuestions(testID);
        currentTestID = testID;
        currentQuestionNum = 0;
    }

    public boolean IsNextQuestion() {
        if (currentQuestionNum < questionList.size() - 1) {
            currentQuestionNum++;
            return true;
        } else {
            return false;
        }
    }

    public boolean IsPrevQuestion() {
        if (currentQuestionNum > 0) {
            currentQuestionNum--;
            return true;
        } else {
            return false;
        }
    }

    public QuestionData getCurrentQuestion() {
        currentQuestion =  questionList.get(currentQuestionNum);
        return currentQuestion;
                
    }

    public ITestDAO getTestDB() {
        if (testDB == null) {
            testDB = DB.getInstance().getFactory().getTestDAO();
        }
        return testDB;
    }

    public TestFacade() {
        testList = new ArrayList<TestData>();
    }

    public List<TestData> getTestList() {
        if (testList.isEmpty()) {
            testList = getTestDB().getList();
        }
        return testList;
    }

    /**
     * @return the currentTestID
     */
    public int getCurrentTestID() {
        return currentTestID;
    }

    /**
     * @param currentTestID the currentTestID to set
     */
    public void setCurrentTestID(int currentTestID) {
        this.currentTestID = currentTestID;
    }

    /**
     * @return the questionList
     */
    public ArrayList<QuestionData> getQuestionList() {
        return questionList;
    }

    /**
     * @return the currentQuestionNum
     */
    public int getCurrentQuestionNum() {
        return currentQuestionNum;
    }

    /**
     * @param currentQuestionNum the currentQuestionNum to set
     */
    public void setCurrentQuestionNum(int currentQuestionNum) {
        this.currentQuestionNum = currentQuestionNum;
    }
}
